import junit.framework.TestCase;

/**
 * Created by zyl on 17-4-20.
 */
import junit.framework.TestResult;
import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.*;
public class MyComplexTest extends TestCase {
    MyComplex a=new MyComplex(1,2);
    MyComplex b=new MyComplex(1,-4);
    MyComplex c=new MyComplex(19,0);
    MyComplex d=new MyComplex(0,-3);
    MyComplex e=new MyComplex(0,0);
    String s="ac:bd";
    int [] m={1,4,3,2};
    @Test
    public void testgetRealPart() throws Exception {
        assertEquals(1, MyComplex.getRealPart(1));
        assertEquals(-1, MyComplex.getRealPart(-1));
        assertEquals(5, MyComplex.getRealPart(5));
        assertEquals(22, MyComplex.getRealPart(22));
        assertEquals(-100, MyComplex.getRealPart(-100));
        assertEquals(0, MyComplex.getRealPart(0));
    }
    @Test
    public void testgetImaginePart() throws Exception {
        assertEquals(1, MyComplex.getImaginePart(1));
        assertEquals(-1, MyComplex.getImaginePart(-1));
        assertEquals(5, MyComplex.getImaginePart(5));
        assertEquals(22, MyComplex.getImaginePart(22));
        assertEquals(-100, MyComplex.getImaginePart(-100));
        assertEquals(0, MyComplex.getImaginePart(0));
    }
    @Test
    public void testadd() throws Exception {
        assertEquals("(2.0-2.0i)", a.add(b).toString());
        assertEquals("(20.0+2.0i)", a.add(c).toString());
        assertEquals("(1.0-1.0i)", a.add(d).toString());
        assertEquals("(1.0+2.0i)", a.add(e).toString());
    }
    @Test
    public void testminus() throws Exception {
        assertEquals("(0.0+6.0i)", a.minus(b).toString());
        assertEquals("(-18.0+2.0i)", a.minus(c).toString());
        assertEquals("(1.0+5.0i)", a.minus(d).toString());
        assertEquals("(1.0+2.0i)", a.minus(e).toString());
    }
    @Test
    public void testmultiply() throws Exception {
        assertEquals("(9.0-2.0i)", a.multiply(b).toString());
        assertEquals("(19.0+38.0i)", a.multiply(c).toString());
        assertEquals("(6.0-3.0i)", a.multiply(d).toString());
        assertEquals("(0.0)", a.multiply(e).toString());
    }
    @Test
    public void testcharAt() throws Exception {
        assertEquals('a',s.charAt(0));
    }
    @Test
    public void testsplit() throws Exception{
        String [] n= s.split(":");
        assertEquals("bd",n[1]);
    }
    @Test
    public void testsort() {
        Arrays.sort(m);
        assertEquals(4,m[3]);
    }
    @Test
    public void testbinarySearch() throws Exception{
        int x1;
        x1=Arrays.binarySearch(m,2);
        assertEquals(-2,x1);
    }
}

